package application;
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class ConsoleReader {

	private Scanner scaner;
	PrintStream out;
	private String[] args;
	
	public ConsoleReader(InputStream is, PrintStream out){
		scaner = new Scanner(is);
		this.out = out;
	}
	
	public boolean hasNextCommand(){
		return scaner.hasNext();
	}
	
	public String nextCommand(){
		String userLine = scaner.nextLine();
		String[] parts = userLine.split(" ");
		args = getArgs(parts);
		return parts[0];
	}
	
	public void print(String str){
		out.println(str);
	}
	
	public String[] getArgs(){
		return args;
	}
	
	
	public void close(){
		scaner.close();
	}
	
    private String[] getArgs(String ... parts){
        int newSize = parts.length - 1;
        String[] newParts = new String[newSize];
        for(int a = 1; a < parts.length; a++){
            newParts[a-1] = parts[a];
        }
        
        return newParts;
    }
}
